package com.jnxx.basic.util;

import lombok.Data;

@Data
public class AjaxResult {

    private Boolean success = true;

    private String message = "操作成功！";

    private String code = "0";

    private Object data = null;

    public AjaxResult() {
    }

    public static AjaxResult success(){
        return new AjaxResult();
    }

    public AjaxResult setSuccess(Boolean success) {
        this.success = success;
        return this;
    }

    public AjaxResult setMessage(String message) {
        this.message = message;
        return this;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public AjaxResult setData(Object data) {
        this.data = data;
        return this;
    }

    public static AjaxResult me(){
        return new AjaxResult();
    }

    public static AjaxResult success(String code, String message){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setMessage(message);
        ajaxResult.setCode(code);
        return ajaxResult;
    }

    public static AjaxResult success(String code, String message, Object data){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setMessage(message);
        ajaxResult.setCode(code);
        ajaxResult.setData(data);
        return ajaxResult;
    }

    public static AjaxResult success(Object data){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setData(data);
        return ajaxResult;
    }

    public static AjaxResult error(){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(false);
        ajaxResult.setCode("10");
        return ajaxResult;
    }

    public static AjaxResult error(String code, String message){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(false);
        ajaxResult.setMessage(message);
        ajaxResult.setCode(code);
        return ajaxResult;
    }

    public static AjaxResult error(String code, String message, Object data){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(false);
        ajaxResult.setMessage(message);
        ajaxResult.setCode(code);
        ajaxResult.setData(data);
        return ajaxResult;
    }
}
